package javabase.schoolwork.day6_11;

import java.util.Date;

/**
 * @author fance
 * @date 2018/6/12 8:35
 */
public class Account {
    private String name;
    private String pwd;
    private double balance;
    private Date openAccountDate;
    private double interest;
    private User User;


    public Account(String name, String pwd, Date openAccountDate,User User) {
        this.name = name;
        this.pwd = pwd;
        this.openAccountDate = openAccountDate;
        this.User = User;
    }
    public String getName() {
        return name;
    }
    public void setName(String name) {
        this.name = name;
    }
    public String getPwd() {
        return pwd;
    }
    public void setPwd(String pwd) {
        this.pwd = pwd;
    }
    public double queryBalance() {
        return balance;
    }
    public synchronized boolean deposit(double balance) {
        if(balance<=0) {
            return false;
        }
        this.balance += balance;
        System.out.println("存入"+balance+"元");
        return true;
    }
    public synchronized boolean withDraw(double balance) {
        if(this.balance < balance || balance <= 0) {
            return false;
        }
        this.balance -= balance;
        System.out.println("取出"+balance+"元");
        return true;
    }
    public Date getOpenAccountDate() {
        return openAccountDate;
    }
    public void setOpenAccountDate(Date openAccountDate) {
        this.openAccountDate = openAccountDate;
    }

    public double getInterest() {
        return interest;
    }

    public void setInterest(double interest) {
        this.interest = interest;
    }

    public void display() {
        System.out.println(this.toString());
    }

    public User getUser() {
        return User;
    }
    public void setUser(User User) {
        this.User = User;
    }

    @Override
    public String toString() {
        return "Account [name=" + name + ", pwd=" + pwd + ", balance=" + balance +"User"+User.getDesc()+ "]";
    }

}
